package edu.sctu.renpingan.httpclient;


import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.*;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.util.EntityUtils;

import java.io.IOException;

/**
 * Created by Administrator on 2015/6/25.
 */
public class HttpClientGet {
    HttpClientBuilder httpClientBuilder =  HttpClientBuilder.create();
    CloseableHttpClient closeableHttpClient = httpClientBuilder.build();

    public void  httpGet() throws IOException {
        HttpGet httpGet = new HttpGet("http://www.baidu.com");

           HttpResponse httpResponse = closeableHttpClient.execute(httpGet);

           HttpEntity httpEntity = httpResponse.getEntity();
           System.out.println(httpResponse.getStatusLine());

        if (httpEntity != null){

            System.out.println(httpEntity.getContentEncoding());

            System.out.println(EntityUtils.toString(httpEntity));


        }
        closeableHttpClient.close();
    }

}
